from typing import *


class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

# 输入：head = [18,6,10,3]
# 输出：[18,6,6,2,10,1,3]
class Solution:
    def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:
        p = head
        def gcd(a,b):
            return a if b == 0 else gcd(b , a % b)
        while p.next:
            node = ListNode(val = gcd(p.val,p.next.val),next = p.next)
            p.next = node
            p = p.next.next
        return head
def gcd(a,b):
    return a if b == 0 else gcd(b , a % b)
print(gcd(18,11)) 
